<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="java.util.List"%>
<%@ page import="com.google.appengine.api.users.User"%>
<%@ page import="com.google.appengine.api.users.UserService"%>
<%@ page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory"%>
<%@ page import="com.google.appengine.api.datastore.DatastoreService"%>
<%@ page import="com.google.appengine.api.datastore.Query"%>
<%@ page import="com.google.appengine.api.datastore.Entity"%>
<%@ page import="com.google.appengine.api.datastore.FetchOptions"%>
<%@ page import="com.google.appengine.api.datastore.Key"%>
<%@ page import="com.google.appengine.api.datastore.KeyFactory"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<html>
<head>
<title>LLC UH Manoa: Take Quiz for course CHN883</title>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />

</head>

<body>

  <form action="/send" method="post">

    <%
        //pageContext.setAttribute("email", pageContext.getAttribute("email"));
        pageContext.setAttribute("email", request.getParameter("email"));

        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        Query query = new Query("Quiz");
        List<Entity> questions = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(20));

        for (Entity question : questions)
        {

            pageContext.setAttribute("chinese", question.getProperty("chinese"));
            pageContext.setAttribute("instruction", question.getProperty("instruction"));
            pageContext.setAttribute("quizquestion", question.getProperty("question"));
            pageContext.setAttribute("a", question.getProperty("a"));
            pageContext.setAttribute("b", question.getProperty("b"));
            pageContext.setAttribute("c", question.getProperty("c"));
            pageContext.setAttribute("d", question.getProperty("d"));
            pageContext.setAttribute("key", question.getKey());
    %>
    <h2>${fn:escapeXml(chinese)}</h2>
    <h3>${fn:escapeXml(instruction)}</h3>
    <p>${fn:escapeXml(quizquestion)}</p>
    <p>
    <blockquote><input type="radio" name="${fn:escapeXml(key)}" value="${fn:escapeXml(a)}" required="required"> ${fn:escapeXml(a)}
      </p></blockquote>
    <p>
    <blockquote><input type="radio" name="${fn:escapeXml(key)}" value="${fn:escapeXml(b)}"> ${fn:escapeXml(b)}
      </p></blockquote>
    <p>
    <blockquote><input type="radio" name="${fn:escapeXml(key)}" value="${fn:escapeXml(c)}"> ${fn:escapeXml(c)}
      </p></blockquote>
    <p>
    <blockquote><input type="radio" name="${fn:escapeXml(key)}" value="${fn:escapeXml(d)}"> ${fn:escapeXml(d)}
      </p></blockquote> <br>
    <%
        }
    %>


    <!-- Closing FORM element -->
    <br> <br> <input type="submit" id="el08" value="Submit Your Answers" /> <input type="hidden" name="email" value="${fn:escapeXml(email)}" />
  </form>


</body>
</html>